<?php
//用户订单
class Order
{
    // 返回内部订单ID
    // @comment: 无论orderId 是内部ID还是OrderNo, 都必须使用内部ID
    public static function getInternalOrderId ($orderNo)
    {
        if ($orderNo < 10000000)
        {
            return (int) $orderNo;
        }
        else
        {
            $orderId = DB::select('id')
                ->from('app_order')
                ->where('orderNo', '=', $orderNo)
                ->limit(1)
                ->execute()
                ->get('id');

            return (int) $orderId;
        }
    }

    public static function ordersGroupByShop($orders)
    {
        $ret = array();
        foreach ($orders as $rs)
        {
            $shopId = Arr::get($rs, 'shopId');
            if (! array_key_exists($ret, $shopId))
                $ret[$shopId] = array('orders' => array(), 'shopName' => App_Shop::name($shopId) );

            $ret[$shopId]['orders'][] = $rs;
        }

        return $ret;
    }

	//订单数
	//$user object 用户对象
    public static function statsCount ($user)
    {
        $stats = array(
            'total' => 0,
            'unPaid'  => 0,
            'hasPaid' => 0,
            'hasSendGoods' => 0,
        );

        $query = DB::select(array('count("id")', 'counts'), 'status')
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->group_by('status')
            ->execute();

        $total = 0;
        foreach ($query as $rs)
        {
            $counts = $rs['counts'];
            $status = $rs['status'];

            if ($status == 0)
                $stats['unPaid'] = $counts;
            else if ($status == 1)
                $stats['hasPaid'] = $counts;
            else if ($status == 2)
                $stats['hasSendGoods'] = $counts;

            $total += $counts;
        }

        $stats['total'] = $total;

        return $stats;
    }

    public static function getOrderId ($orderNo)
    {
        $info = self::basicInfo ($orderNo);
        return Arr::get($info, 'id', 0);
    }

    public static function getOrderNo ($orderNo)
    {
        $info = self::basicInfo ($orderNo);
        return Arr::get($info, 'orderNo', $orderNo);
    }

    public static function firstGoodsInfo ($orderNo)
    {
        $info = self::basicInfo ($orderNo);
        $orderId = Arr::get($info, 'id', 0);

        if (empty($orderId))
            return array();

        $goodsId = DB::select('goodsId')
            ->from('app_order_goods')
            ->where('orderId', '=', $orderId)
            ->limit(1)
            ->execute()
            ->get('goodsId');

        return App_Goods::info($goodsId);
    }

	//订单列表
	//listWheres array 订单查询条件
    public static function infoList ($offset, $limit, $listWheres = array())
    {
        $orders = array();
        $query = DB::select('a.*')
            ->from(array('app_order', 'a'))
            ->order_by('a.changed', 'desc');

        foreach ($listWheres as $rs)
        {
            if (is_array($rs))
            {
                $query->where($rs[0], $rs[1], $rs[2]);
            }
        }

        $query = $query->offset($offset)->limit($limit)->execute();

        foreach ($query as $rs)
        {
            $rs['statusName']  = self::orderStatusName ($rs['status']);
            $rs['title'] = utf8::substr($rs['title'], 0, 50) . '...';
            $rs['shortTitle'] = utf8::substr($rs['title'], 0, 15) . '...';

            $orders[] = $rs;
        }

        return $orders;
    }


	// 结算列表
	// listWheres array 订单查询条件
    public static function moneyList ($offset, $limit, $listWheres = array())
    {
        $orders = array();
        $count = DB::select(array('count("a.id")', 'counts'))
            ->from(array('app_order', 'a'))
            ->join(array('mod_payment_transaction', 'b'), 'LEFT')
            ->on('a.transactionId', '=', 'b.id')
            ->where('a.status', '=', '99');

        $query = DB::select('a.*', 'b.platform')
            ->from(array('app_order', 'a'))
            ->join(array('mod_payment_transaction', 'b'), 'LEFT')
            ->on('a.transactionId', '=', 'b.id')
            ->where('a.status', '=', '99')
            ->order_by('a.paidTime', 'desc');

        foreach ($listWheres as $rs)
        {
            if (is_array($rs))
            {
                $query->where($rs[0], $rs[1], $rs[2]);
                $count->where($rs[0], $rs[1], $rs[2]);
            }
        }

        $count = $count->execute()->get('counts');
        $query = $query->offset($offset)->limit($limit)->execute();

        foreach ($query as $rs)
        {
            $rs['statusName']  = self::orderStatusName ($rs['status']);
            $rs['title'] = utf8::substr($rs['title'], 0, 50) . '...';
            $rs['shortTitle'] = utf8::substr($rs['title'], 0, 15) . '...';

            $orders[] = $rs;
        }

        return array($count, $orders);
    }


    public static function userHasOrder ($uid, $orderNo)
    {
        $order = self::basicInfo($orderNo);
        $orderUid = Arr::get($order, 'uid');

        return $uid == $orderUid;
    }

    // 计算订单应该退款的金额
    public static function getMoneyRefund ($orderDetail, $giftList = NULL)
    {
        if ($orderDetail['orderType'] != 'TOFRIENDS')
        // 普通订单退款金额计算
        {
	        if ($orderDetail['status'] > 0 && $orderDetail['status'] < 6)
	        {
	            return $orderDetail['moneyTotal'];
	        }
	        else
	        {
	            return 0;
	        }
        }
        else
        // 红包订单退款金额 = 支付金额 - 已领取红包金额
        {
	        if ($orderDetail['status'] > 0 && $orderDetail['status'] < 6)
	        {
	            $money1 = $orderDetail['moneyTotal'];
                $GoodsQuantity = $orderDetail['goodsTotalQuantity'];
                $GoodsMoney    = $orderDetail['goodsTotalMoney'];
                $goodsPrice    = $GoodsMoney / $GoodsQuantity;
                $goodsUsed     = count(arr::get($giftList, 'users', array()));
                $moneyUsed     = $goodsPrice * $goodsUsed;

                $moneyRefund   = $money1 - $moneyUsed;
                $moneyRefund   = $moneyRefund > 0 ? $moneyRefund : 0;

                return $moneyRefund;
	        }
	        else
	        {
	            return 0;
	        }
        }
    }

    public static function search ($wheresList, $start = NULL, $limit = NULL)
    {
        $query = DB::select()
            ->from('app_order');

        foreach ($wheresList as $w)
        {
            $query->where($w[0], $w[1], $w[2]);
        }

        if ($start !== NULL)
            $query->offset($start);

        if ($limit > 0)
            $query->limit($limit);

        return $query->execute()->as_array();
    }

    // 订单行程中发起申诉
    public static function shensu ($orderNo)
    {
        try {
            $orderDetail = self::detail($orderNo);
            $status      = Arr::get($orderDetail, 'status');
            $paymentId   = Arr::get($orderDetail, 'paymentId');

            if ($status != 3)
                throw new Exception("订单发起申诉时,状态无效: status=$status");

            $orderId     = Arr::get($orderDetail, 'id');
            DB::update('app_order')
                ->set(array(
                    'status' => 31,
                    'changed' => DB::expr('unix_timestamp(now())'),
                ))
                ->where('id', '=', $orderId)
                ->execute();

            // 创建申诉处理记录
            $shensu = new Order_Shensu($orderId);
            $shensu->create();

            $log = new Order_Log($orderId);
            $log->add("游客向哇吖发出申诉");
            $log->add("哇吖接受游客的申诉申请，并会尽快与游客取得联系");
            Util_Notice::notice_refund_front($orderDetail);
            return TRUE;
        } 
        catch (Exception $e)
        {
            Kohana::$log->add(Log::ERROR, "App_Order::shensu($orderNo): FAILED, ". $e->getMessage());
        }
 
        return FALSE;
    }
 
 

 

    // 订单退款自动执行，检查订单状态，只针对已付款状态订单自动退款
    public static function refundSafety ($orderNo)
    {
        try {
            $orderDetail = self::detail($orderNo);
            $status      = Arr::get($orderDetail, 'status');
            $paymentId   = Arr::get($orderDetail, 'paymentId');
            $moneyRefund = Arr::get($orderDetail, 'moneyTotalRMB');    // 退款单位: 分

            if ($status != 2)
                throw new Exception("订单发起退款时,状态无效: status=$status");

            $orderId     = Arr::get($orderDetail, 'id');
            DB::update('app_order')
                ->set(array(
                    'status' => 4,
                    'changed' => DB::expr('unix_timestamp(now())'),
                ))
                ->where('id', '=', $orderId)
                ->execute();

            $log = new Order_Log($orderId);
            $log->add("哇吖启动了退款流程");

            $refund = new Payment_Refund($orderId);
            $refund->add();
//            Util_Notice::notice_refund_front($orderDetail);
            return TRUE;

            if ($paymentId == 1)
            {
                if (Payment_Weixin_Refund::order($orderDetail, $moneyRefund))
                {
                    // 微信实时返回退款状态
                    App_Order::setOrderRefunded($orderNo);
                }
            }
            else if ($paymentId == 2)
            {
                // 支付宝退款走有密接口（人工批量线上退款)
                $alipay = new Payment_Alipay_Refund();
                $alipay->addRefundOrder($orderDetail, $moneyRefund);
            }
            else
            {
                throw new Exception("无效的支付方式: paymentId=$paymentId");
            }

            Kohana::$log->add(Log::DEBUG, "App_Order::refundSafety($orderNo): SUCCESS, money=$moneyRefund");

            return TRUE;
        } 
        catch (Exception $e)
        {
            Kohana::$log->add(Log::ERROR, "App_Order::refundSafety($orderNo): FAILED, ". $e->getMessage());
        }
 
        return FALSE;
 
 
    }

    // 订单退款执行, 不检查订单状态，强制退款
    public static function refund ($orderNo, $moneyRefund = 0)
    {
        try {
            $orderDetail = App_Order::detail($orderNo);
            $paymentId   = Arr::get($orderDetail, 'paymentId');

            if ($paymentId == 1)
            {
                if (Payment_Weixin_Refund::order($orderDetail, $moneyRefund))
                {
                    // 微信实时返回退款状态
                    App_Order::setOrderRefunded($orderNo);
                }
            }
            else if ($paymentId == 2)
            {
                $alipay = new Payment_Alipay_Refund();
                $alipay->addRefundOrder($orderDetail, $moneyRefund);
            }
            else
            {
                throw new Exception("无效的支付方式: paymentId=$paymentId");
            }

            Kohana::$log->add(Log::DEBUG, "App_Order::refund($orderNo): SUCCESS, money=$moneyRefund");

            return TRUE;
        } 
        catch (Exception $e)
        {
            Kohana::$log->add(Log::ERROR, "App_Order::refund($orderNo): FAILED, ". $e->getMessage());
        }
 
        return FALSE;
    }

	//不同用户的订单
	//$user object 用户对象
	//$type string 类型
    public static function listByUser($user, $type = NULL)
    {
        $orders = array();
        $uid = $user->getUserUid();
        if ($uid == 0)
            return $orders;

        $query = DB::select('a.*', 'b.orderId', 'b.goodsId', 'b.goodsPrice', 'b.goodsAttrId', 'b.quantity')
            ->from(array('app_order', 'a'))
            ->join(array('app_order_goods', 'b'), 'LEFT')
            ->on('a.id', '=', 'b.orderId')
            ->where('a.uid', '=', $uid)
            ->group_by('a.id')
            ->order_by('a.changed', 'desc');

        if (! empty($type))
        {
            if ($type == 'cancelled')
                $query->where('a.status', '=', 11);
            else if ($type == 'finished')
                $query->where('a.status', 'in', array(3, 6));
            else if ($type == 'doing' || $type == 'unfinished')
                $query->where('a.status', 'not in', array(3, 6, 11, 12));
        }

        $query = $query->execute();

        foreach ($query as $rs)
        {
            $goodsId = $rs['goodsId'];
            $attrId  = $rs['goodsAttrId'];
            $quantity= $rs['quantity'];
            
            if (! empty($type) && $type == 'finished')
            {
                $show = new App_Show();
                $shaidan_id = $show -> get_shaidan_id($uid, $rs['orderId']);
                $rs['shaidan_id'] = empty($shaidan_id) ? 0 : $shaidan_id;
                
                $pinglun = new App_Order_Pinglun();
                $is_pinglun = $pinglun->has_pinglun($uid, $rs['orderId']);
                
                $rs['is_pinglun'] = $is_pinglun;
            }

            $rs['goods'] = App_Goods::basicInfo($goodsId, $attrId, $quantity);
            $rs['statusName']  = self::orderStatusName ($rs['status']);
            $rs['deliverName'] = App_Deliver::getName($rs['deliverId']);
            $rs['title'] = utf8::substr($rs['title'], 0, 50) . '...';
            $rs['shortTitle'] = utf8::substr($rs['title'], 0, 15) . '...';
            $rs['shopName']   = App_Shop::name($rs['shopId']);
            $orders[] = $rs;
        }
        
        return $orders;
    }

    //
    // 订单基本信息
    // @param $orderNO 订单内部表格ID 或者 订单号
    // @return array $orderInfo
    //
    public static function basicInfo ($orderNo)
    {
        if ($orderNo < 10000000)
        {
            $query = DB::select()
            ->from('app_order')
            ->where('id', '=', $orderNo)
            ->limit(1)
            ->execute();
        }
        else
        {
            $query = DB::select()
            ->from('app_order')
            ->where('orderNo', '=', $orderNo)
            ->limit(1)
            ->execute();
        }

        return $query->current();
    }

    // 设置订单支付完成
    public static function setOrderPaid ($orderNo, $transactionId = NULL, $paymentId = 0, $merchantId = 0)
    {
        self::resetStatus($orderNo, 1);

        $update = array();

        if (! empty($transactionId))
            $update['transactionId'] =  $transactionId;

        if ($paymentId > 0)
            $update['paymentId'] = $paymentId;

        if ($merchantId > 0)
            $update['mchId'] = $merchantId;

        if (! empty($update))
        {
	        DB::update('app_order')
                ->set($update)
	            ->where('orderNo', '=', $orderNo)
	            ->limit(1)
	            ->execute();
        }

        // 设置团购任务状态
        App_Order_Tuan::orderPaid($orderNo);

        // 更新订单商品的售卖数量
        App_Order_Goods::updateCountsSale ($orderNo);

        // 执行返利
        // App_Share_Money::orderPaid2Share ($orderNo);


        //
        // 发送自定义微信通知
        //
        /*
        $order   = self::basicInfo($orderNo);
        $oSName  = App_Shop::name(Arr::get($order, 'shopId'));
        $oTitle  = utf8::substr(Arr::get($order, 'title'), 0, 10) . '...';
        $oLink   = url::site('/order/detail/'.$orderNo, 'http', FALSE);
        $oBuyerUid = Arr::get($order, 'uid');
        $message = "支付成功通知，您在【{$oSName}】购买的\"$oTitle\"商品已支付成功, 卖家将尽快给您发货。<a href=\"$oLink\">查看详情</a>";
        App_Message::sendUserCustomMessage($oBuyerUid, $message);
        */
    }

    // 设置订单发货
    public static function setOrderDelivered($orderNo, $deliverNo)
    {
        $row = array(
            'status'  => 2,
            'changed' => DB::expr('unix_timestamp(now())'),
            'deliverNo' => $deliverNo,
        );

        $rows = DB::update('app_order')
            ->set($row)
            ->where('orderNo', '=', $orderNo)
            ->limit(1)
            ->execute();

        return $rows > 0;
    }

    // 设置订单结束
    public static function setOrderFinished($orderNo)
    {
        return self::resetStatus($orderNo, 99);
    }
    // 设置评论完成
    public static function setCommentFinished($orderNo)
    {
        return self::resetStatus($orderNo, 7);
    }

    // 设置订单退款中
    public static function setOrderRefunding($orderNo)
    {
        return self::resetStatus($orderNo, 5);
    }

    // 设置订单退款完成
    public static function setOrderRefunded($orderNo)
    {
        return self::resetStatus($orderNo, 6);
    }

    public static function isBuyerFirstOrderPaid ($uid, $orderId)
    {
        $query = DB::select('id')
            ->from('app_order')
            ->where('status', '>', 0)
            ->where('status', '<', 10)
            ->where('uid', '=', $uid)
            ->order_by('paidTime', 'asc')
            ->limit(1)
            ->execute();

        if ($query->count() == 0)
            return FALSE;

        $order = $query->current();
        if ($order['id'] == $orderId)
            return TRUE;
        else
            return FALSE;
    }


    public static function resetStatus ($orderNo, $statusId)
    {
        if ($orderNo < 10000000)
        {
            $query = DB::select()
            ->from('app_order')
            ->where('id', '=', $orderNo)
            ->limit(1)
            ->execute();
        }
        else
        {
            $query = DB::select()
            ->from('app_order')
            ->where('orderNo', '=', $orderNo)
            ->limit(1)
            ->execute();
        }

        if ($query->count() == 0)
            return NULL;

        $detail  = $query->current();
        $orderId = $detail['id'];
        if ($orderId > 0)
        {
            $row = array('status' => $statusId, 'changed' => DB::expr('unix_timestamp(now())'));
            if ($statusId == 1)
                $row['paidTime'] = DB::expr('unix_timestamp(now())');

            DB::update('app_order')
                ->set($row)
                ->where('id', '=', $orderId)
                ->execute();
        }
    }

	//订单打印详细
	//$orderNo 订单编号
    public static function detailPrint ($orderNo, $subOrderUid = NULL)
    {
        if ($orderNo < 10000000)
        {
            $query = DB::select()
            ->from('app_order')
            ->where('id', '=', $orderNo)
            ->limit(1)
            ->execute();
        }
        else
        {
            $query = DB::select()
            ->from('app_order')
            ->where('orderNo', '=', $orderNo)
            ->limit(1)
            ->execute();
        }

        if ($query->count() == 0)
            return NULL;

        $detail  = $query->current();
        $orderId = $detail['id'];

        if ($detail['status'] == 0 &&
            $detail['moneyTotal'] == 0)
        {
            self::setOrderPaid($detail['orderNo']);
            $query = DB::select()
                ->from('app_order')
                ->where('id', '=', $orderId)
                ->limit(1)
                ->execute();
            $detail = $query->current();
        }

        $detail['arrGoodsInfo']= self::arrGoodsInfo($orderId);
        $detail['statusName']  = self::orderStatusName ($detail['status']);
        $detail['deliverName'] = App_Deliver::getName($detail['deliverId']);
        $detail['invoice'] = self::getOrderInvoice($orderId);

        $goodsTotalMoney = 0;
        $goodsTotalQuantity = 0;
        foreach ($detail['arrGoodsInfo'] as $goods)
        {
            $goodsTotalMoney += $goods['money'];
            $goodsTotalQuantity += $goods['quantity'];
        }

        $detail['goodsTotalMoney'] = $goodsTotalMoney;
        $detail['goodsTotalQuantity'] = $goodsTotalQuantity;

        if ($detail['orderType'] == 'TOFRIENDS')
        {
            $subOrderUid = (int) $subOrderUid;
            $gift = App_Order_Gift::detail($orderNo, User::getUserFromUid($subOrderUid));
            $address = Arr::get($gift, 'userAddress', array());

            $detail['addrUserName']   = Arr::get($address, 'addrUserName');
            $detail['addrTelNumber']  = Arr::get($address, 'addrTelNumber');
            $detail['addrDetailInfo'] = Arr::get($address, 'addrDetailInfo');
            $detail['addrPostalCode'] = Arr::get($address, 'addrPostalCode');

            $countsGoods = 0;
            $moneyGoods  = 0;
            foreach ($detail['arrGoodsInfo'] as & $rs)
            {
                $rs['quantity'] = 1;
                $rs['money'] = $rs['price'];

                $moneyGoods += $rs['money'];
                $countsGoods += 1;
            }

            $detail['goodsTotalQuantity'] = $countsGoods;
            $detail['goodsTotalMoney']    = $moneyGoods;
            $detail['moneyTotal'] = 0;
        }

        return $detail;
    }



	//订单详细
	//$orderNo 订单编号
    public static function detail ($orderNo)
    {
        if ($orderNo < 10000000)
        {
            $query = DB::select()
            ->from('app_order')
            ->where('id', '=', $orderNo)
            ->limit(1)
            ->execute();
        }
        else
        {
            $query = DB::select()
            ->from('app_order')
            ->where('orderNo', '=', $orderNo)
            ->limit(1)
            ->execute();
        }

        if ($query->count() == 0)
            return NULL;

        $detail  = $query->current();
        $orderId = $detail['id'];

        if ($detail['status'] == 0 &&
            $detail['moneyTotal'] == 0)
        {
            self::setOrderPaid($detail['orderNo']);
            $query = DB::select()
                ->from('app_order')
                ->where('id', '=', $orderId)
                ->limit(1)
                ->execute();
            $detail = $query->current();
        }
        $detail['startDay'] = date('Y.m.d',strtotime($detail['startDay']));
        $detail['stopDay'] = date('Y.m.d',strtotime($detail['stopDay']));
        $detail['statusName']  = self::orderStatusName ($detail['status']);
        $detail['shortTitle'] = utf8::substr($detail['title'], 0, 20) . '...';

        $guider  = new Guider(Arr::get($detail, 'shopId'));
        $detail['guider']  = $guider->getUserInfo();

        $tourist = new Tourist(Arr::get($detail, 'uid'));
        $detail['tourist'] = $tourist->getUserInfo();

        $service = Goods::factory($detail['goodsType'], $detail['goodsId']);
        $detail['servicePrice']   = $service->getPrice(TRUE, FALSE);
        $detail['serviceName']    = $service->getName();

        return $detail;
    }

	//创建订单
	//$arrBuyInfo	array	商品信息
	//$coins		int		账户余额抵扣数(分)
	//$ticketId		int		优惠券
	//$addressId	int		地址编号	
	//$deliverId	int		快递编号
	//$paymentId	int		支付编号
	//$invoiceInfo	array	发票编号
    //$comments     string  用户备注
    //$orderType    string  订单类型
    //$tuanId       int     团购任务ID
    public static function create ($uid, $type, $nid, $persons, $startDay, $stopDay)
    {
        // goods
        $type       = strtoupper($type);
        $goodsData  = array();
        $goodsId    = $nid;
        $goods      = Goods::factory($type, $nid);
        if ($type == 'ACTIVITY' && empty($stopDay))
            $stopDay = $startDay;
        if ($type == 'ZIYING' && empty($stopDay))
        	$stopDay=$goods->getStopDay($startDay);
        
        if($type=='ZIYING'){
        	$goodsPrice = $goods->getPriceByDay($startDay);
        }else{$goodsPrice = $goods->getPrice();}
        $guiderUid  = $goods->getGuiderUid();
        $countsBuy  = $persons;
        $title      = $goods->getName();

        // order
        $orderData = array(
            'status'  => 0,
            'created' => DB::expr('unix_timestamp(now())'),
            'changed' => DB::expr('unix_timestamp(now())'),
        );

        $orderData['title']       = utf8::substr($title, 0, 255);
        $orderData['uid']         = $uid;
        $orderData['shopId']      = $guiderUid;
        $orderData['countsGoods'] = 1;
        $orderData['countsQuantity'] = $countsBuy;
        $orderData['startDay']    = $startDay;
        $orderData['stopDay']     = $stopDay;
        $orderData['goodsId']     = $nid;
        $orderData['goodsType']   = $type;
        $orderData['persons']     = $persons;

        // 金额信息
        $moneyGoods  = $goods->getMoney($startDay, $stopDay, $persons);
        $orderData['moneyCoin']    = 0;
        $orderData['moneyTicket']  = 0;
        $orderData['moneyDeliver'] = 0;
        $orderData['moneyGoods']   = $moneyGoods;
        $orderData['moneyTotal']   = $moneyGoods;
        $orderData['commentsUser'] = '';
        $orderData['orderType']    = 'NORMAL';
        $orderData['tuanId']       = 0;

        list($insert_id, $rows) = DB::insert('app_order')
            ->columns(array_keys($orderData))
            ->values(array_values($orderData))
            ->execute();

        if ($insert_id > 0)
        {
            // 设置订单编号
            $orderId = $insert_id;
            $orderNo = sprintf("%s%06d%s", date("Ymd"), $insert_id, date("Hi"));
            DB::update('app_order')
                ->set(array('orderNo' => $orderNo))
                ->where('id', '=', $orderId)
                ->execute();

            // 记录订单日志
            $log = new Order_Log($orderId);
            if (strtoupper($type) == 'TRACK')
                $log->add("预订了路线订单");
            elseif (strtoupper($type) == 'ZIYING')
            	$log->add("预订了自营项目订单");
            else
                $log->add("预订了活动订单");


            // 更新用户订单数
            App_Account::incAccountOrder($orderData['uid']);

            // 更新线路/活动订单数
            if (! empty($goods))
                $goods->updateCountsOrders();

            // 扣除账户余额
            //$moneyCoinYuan = number_format($moneyCoin/ 100, 2);
            //$message = "余额抵扣{$moneyCoinYuan}元,支付订单: $orderNo";
            //App_Account::addAccountCoin($orderUid, 0 - abs($moneyCoin), $message);

            // 设置订单商品
            //foreach ($goodsData as $rs)
            //{
             //   $rs['orderId'] = $orderId;
              //  list($id, $rows) = DB::insert('app_order_goods')
               //     ->columns (array_keys($rs))
                //    ->values(array_values($rs))
                 //   ->execute();
            //}

            // 处理订单发票
            //self::setOrderInvoice($orderId, $invoiceInfo);

            return $orderNo;
        }
        else
        {
            return 0;
        }
    }

	//移除订单
	//$orderNid 订单id
    public static function remove ($orderNid)
    {
        $info = DB::select()
            ->from('app_order')
            ->where('id', '=', $orderNid)
            ->execute()
            ->current();

        if (empty($info))
            return;

        $status  = Arr::get($info, 'status');
        //$coins   = Arr::get($info, 'moneyCoin', 0);
        $uid     = Arr::get($info, 'uid');
        $orderNo = Arr::get($info, 'orderNo');

        //
        // 未付款和过期的订单可以删除
        // 已支付的订单也可以删除
        //
        if ($status == 0 || $status == 1 || $status >= 100)
        {
            $rows = DB::update('app_order')
                ->set(array('status' => 102))
                ->where('id', '=', $orderNid)
                ->execute();

            $log = new Order_Log($orderNid);
            $log->add("预约订单被删除");

            // 通知游客和导游，预约订单被删除
            Util_Notice::addNotice(-10, Arr::get($info, 'uid'), "预约订单被删除: $orderNo");
            Util_Notice::addNotice(-10, Arr::get($info, 'shopId'), "预约订单被删除: $orderNo");

            return $rows > 0;
        }
        else
        {
            return FALSE;
        }
    }

	//限时自动关闭
	//$user object 用户对象
    public static function autoClose($user)
    {
        if ($user->getUserUid() == 0)
            return;

        $query = DB::select()
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->where('status', '=', 0)
            ->where('created', '<', time() - 86400)
            ->execute();

        foreach ($query as $rs)
        {
            $orderId = $rs['id'];
            $orderNo = $rs['orderNo'];
            $coins   = $rs['moneyCoin'];
            $uid     = $rs['uid'];

            $rows = DB::update('app_order')
                ->set(array('status' => 11))
                ->where('id', '=', $orderId)
                ->execute();

            if ($rows > 0)
            {
                $coinsYuan = number_format($coins / 100, 2);
                $message = "未支付订单$orderNo 已关闭，退还账户余额 $coinsYuan 元";
                App_Account::addAccountCoin($uid, $coins, $message, 0 - $coins); 
            }

        } // foreach 
    }

	//订单商品信息
	//$orderNid int  订单id
    public static function arrGoodsInfo($orderId)
    {
        $query = DB::select()
            ->from('app_order_goods')
            ->where('orderId', '=', $orderId)
            ->execute();

        $ret = array();
        foreach ($query as $rs)
        {
            $goodsInfo = App_Goods::basicInfo($rs['goodsId'], $rs['goodsAttrId']);
            $ret[] = array(
                'goods' => $goodsInfo,
                'price' => $rs['goodsPrice'],
                'quantity' => $rs['quantity'],
                'money'    => $rs['goodsPrice'] * $rs['quantity'],
            );
        }

        return $ret;
    }

	//订单发票
	//$orderNid int   订单id
	//$info		array 发票信息
    public static function setOrderInvoice ($orderId, $info)
    {
        $type  = Arr::get($info, 'invoiceType', 0);
        $cont  = Arr::get($info, 'invoiceContent', 0);
        $title = Arr::get($info, 'invoiceTitle', '');

        $row = array(
            'invoiceType' => App_Invoice::optionName('invoiceType', $type),
            'contentType' => App_Invoice::optionName('invoiceContent', $cont),
            'invoiceTitle'=> trim($title),
        );

        // 不需要发票
        if ($type == 0)
        {
            DB::delete('app_order_invoice')
                ->where('orderId', '=', $orderId)
                ->execute();
        }
        else
        {
            $id = DB::select('id')
                ->from('app_order_invoice')
                ->where('orderId', '=', $orderId)
                ->limit(1)
                ->execute()
                ->get('id');

            if ($id > 0)
            {
                DB::update('app_order_invoice')
                    ->set($row)
                    ->where('orderId', '=', $orderId)
                    ->execute();
            }
            else
            {
                $row['orderId'] = $orderId;
                DB::insert('app_order_invoice')
                    ->columns(array_keys($row))
                    ->values(array_values($row))
                    ->execute();
            }
        }
    }

	//取得订单发票信息
	//$orderNid int   订单id
    public static function getOrderInvoice ($orderId)
    {
        $query = DB::select()
            ->from('app_order_invoice')
            ->where('orderId', '=', $orderId)
            ->limit(1)
            ->execute();

        if ($query->count() == 0)
            return NULL;

        return $query->current();
    }

    public static function options_statusList ()
    {
        $ret = array(
	        0   => '等待付款',
	        1   => '等导游确认',
	        2   => '导游拒绝',
	        3   => '行程中',
	        4   => '申请退款',
	        5   => '退款中',
	        6   => '已退款',
            99  => '已完成',
	        101 => '已过期',
	        102 => '已删除',
        );

        return $ret;
    }

    public static function optionsShopBillStatusList ()
    {
        $ret = array(
	        'READY'  => '准备中',
	        'SUCC'   => '已结算',
	        'FAIL'   => '失败',
        );

        return $ret;
    }

    // 订单的申诉状态
    public static function optionsShensuStatusList ()
    {
        $ret = array(
	        '未处理'  => '未处理',
	        '处理中'  => '处理中',
	        '已处理'  => '已处理',
        );

        return $ret;
    }

    public static function statusAvailAble($orderDetail)
    {
        $ret = array(

            2 => '开始发货',
            3 => '订单完成',
            5 => '开始退款',
            6 => '完成退款',
        );

        return $ret;
    }

	//订单状态
	//$statusId int		状态id
    public static function orderStatusName ($statusId)
    {
        switch ($statusId)
        {
        case 0: 
            return '等待付款';
            break;

        // 已付款
        case 1:
            return '等待接单';
            break;

        case 2:
            return '玩伴拒绝';
            break;

        // 玩伴同意后
        case 3:
            return '行程中';
            break;

        // 申诉
        case 31:
            return '申诉中';
            break;

        case 32:
            return '申诉已处理';
            break;

        // 行程完成
        case 99:
            return '待评价';
            break;

        //评价完成
        case 7:
            return '已完成';
            break;

        // 玩伴拒绝的退款流程
        case 4:
            return '发起退款';
            break;

        case 5: 
            return '退款中';
            break;

        case 6: 
            return '已退款';
            break;

        // 作废流程
        case 101:
            return '已过期';
            break;

        case 102:
            return '已删除';
            break;
        }
    }

    public function __construct ($user = NULL)
    {
        $this->_user = $user;
    }

    // 行程单
    public function unStartedJourneyByUser($user = NULL)
    {
        $user  = empty($user) ? $this->_user : $user;

        $query = DB::select()
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->where('status', 'in', array(0))
            ->order_by('created', 'desc')
            ->execute();

        $guiders = array();
        foreach ($query as $rs)
        {
            $guid = $rs['shopId'];
            if (! isset($guiders[$guid]))
            {
                $guider = new Guider($guid);
                $guiders[$guid] = array(
                    'guider' => $guider->getUserInfo(),
                    'orders' => array(),
                );
            }

            $goods = Goods::factory($rs['goodsType'], $rs['goodsId']);
            $rs['goods'] = $goods->detail();
            $rs['statusName'] = $this->orderStatusName($rs['status']);

            $guiders[$guid]['orders'][] = $rs;
        }

        return $guiders;
    }

    // 已支付的订单列表
    public function listOrdersPaid ($offset, $limit)
    {
        $user = $this->_user;

        if ($user->getUserType() == 'GUIDER')
        {
            $count = DB::select(array('count("id")', 'counts'))
            ->from('app_order')
            ->where('shopId', '=', $user->getUserUid())
            ->where('status', '>=', 2)
            ->where('status', '<', 100)
            ->execute()
            ->get('counts');
 
            $query = DB::select()
            ->from('app_order')
            ->where('shopId', '=', $user->getUserUid())
            ->where('status', '>=', 2)
            ->where('status', '<', 100)
            ->order_by('created', 'desc')
            ->offset($offset)
            ->limit($limit)
            ->execute();
        }
        else
        {
            $count = DB::select(array('count("id")', 'counts'))
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->where('status', '>=', 2)
            ->where('status', '<', 100)
            ->execute()
            ->get('counts');
 
            $query = DB::select()
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->where('status', '>=', 2)
            ->where('status', '<', 100)
            ->order_by('created', 'desc')
            ->offset($offset)
            ->limit($limit)
            ->execute();
 
        }

        $orders = array();
        foreach ($query as $rs)
        {
            $guid   = $rs['shopId'];
            $uid    = $rs['uid'];

            $tourist = User::getUserFromUid($uid);
            $rs['tourist']    = $tourist->getUserInfo();
            $rs['statusName'] = $this->orderStatusName($rs['status']);


            $data = Util_User::getUserInfo($uid);
            $rs['userDetail'] = $data;

            $orders[] = $rs;
        }

        return array($count, $orders);
    }

    // 已支付的游客的订单列表
    public function listOrdersByTourist ($offset, $limit)
    {
        $user = $this->_user;

        $count = DB::select(array('count("id")', 'counts'))
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->where('status', '>=', 1)
            ->where('status', '<', 100)
            ->execute()
            ->get('counts');
 
        $query = DB::select()
            ->from('app_order')
            ->where('uid', '=', $user->getUserUid())
            ->where('status', '>=', 1)
            ->where('status', '<', 100)
            ->order_by('created', 'desc')
            ->offset($offset)
            ->limit($limit)
            ->execute();

        $orders = array();
        foreach ($query as $rs)
        {
            $guid   = $rs['shopId'];
            $uid    = $rs['uid'];

            $guider = new Guider($guid);
            $rs['guider']     = $guider->getUserInfo();
            $rs['statusName'] = $this->orderStatusName($rs['status']);

            $orders[] = $rs;
        }

        return array($count, $orders);
    }


    public function getActivityOrderDays ($activityId)
    {
        $query = DB::select(DB::expr('distinct(`startDay`) as startDay'))
            ->from('app_order')
            ->where('goodsType', '=', 'ACTIVITY')
            ->where('goodsId', '=', $activityId)
            ->where('status', 'in', array(3, 99))
            ->execute();

        $days = array();
        foreach ($query as $rs)
        {
            $days[] = $rs['startDay'];
        }

        return $days;
    }

    public function getActivityOrderPersons ($activityId)
    {
        $query = DB::select(DB::expr('sum(`persons`) as persons'))
            ->from('app_order')
            ->where('goodsType', '=', 'ACTIVITY')
            ->where('goodsId', '=', $activityId)
            ->where('status', 'in', array(3, 99))
            ->execute();

        if ($query->count() > 0)
        {
            $current = $query->current();
            return Arr::get($current, 'persons', 0);
        }
        else
        {
            return 0;
        }
    }



    // 订单申请列表 (只面向导游, 订单状态属于已支付未审核:1，已支付被拒绝:2)
    public function listOrdersRequest ($offset, $limit)
    {
        $user = $this->_user;

        $count = DB::select(array('count("id")', 'counts'))
        ->from('app_order')
        ->where('shopId', '=', $user->getUserUid())
        ->where('status', '=', 1)
        ->execute()
        ->get('counts');
 
        $query = DB::select()
        ->from('app_order')
        ->where('shopId', '=', $user->getUserUid())
        ->where('status', '=', 1)
        ->order_by('created', 'desc')
        ->offset($offset)
        ->limit($limit)
        ->execute();

        $orders = array();
        foreach ($query as $rs)
        {
            $guid   = $rs['shopId'];
            $uid    = $rs['uid'];

            $tourist = User::getUserFromUid($uid);
            $rs['tourist']    = $tourist->getUserInfo();
            $rs['statusName'] = $this->orderStatusName($rs['status']);

            $orders[] = $rs;
        }

        return array($count, $orders);
    }

    // 处理预约(订单)申请
    public function verifyRequest ($orderNo, $action, $reason)
    {
        $action = strtoupper($action);
        $reason = utf8::substr($reason, 0, 250);
        if ($action == 'OK')
        {
            $update = array(
                'status'       => 3,
                'commentsSaler'=> NULL,
                'changed'      => DB::expr('unix_timestamp(now())'),
            );
        }
        else
        {
            $update = array(
                'status'       => 2,
                'commentsSaler'=> $reason,
                'changed'      => DB::expr('unix_timestamp(now())'),
            );
        }

        $rows = DB::update('app_order')
            ->set($update)
            ->where('orderNo', '=', $orderNo)
            ->execute();

        // 记录订单日志
        if ($rows > 0)
        {
            $touristUid = DB::select('uid')
                ->from('app_order')
                ->where('orderNo', '=', $orderNo)
                ->execute()
                ->get('uid');


            $log = new Order_Log($orderNo);
            if ($action == 'OK')
            {
                $data = DB::select('shopId','title','startDay','stopDay','moneyTotalRMB','persons')
                    ->from('app_order')
                    ->where('orderNo', '=', $orderNo)
                    ->execute()
                    ->current();
                $sd = Arr::get($data,'startDay');
                $sd = date('Y年m月d日',strtotime($sd));
                $log->add("玩伴接受了预定,行程将于".$sd."开始");
                $this->ok_notice($touristUid,Arr::get($data,'shopId'),Arr::get($data,'title'),
                    Arr::get($data,'startDay'),Arr::get($data,'stopDay'),Arr::get($data,'persons'),
                    Arr::get($data,'moneyTotalRMB')/100);
//                Util_Notice::addNotice(-10, $touristUid, "预订被导游审批通过");
            }
            else
            {
                $data = DB::select('shopId','title')
                    ->from('app_order')
                    ->where('orderNo', '=', $orderNo)
                    ->execute()
                    ->current();
                $log->add("玩伴拒绝了预定,原因:$reason");
                $this->reject_notice($touristUid,Arr::get($data,'shopId'),Arr::get($data,'title'),$reason);
//                Util_Notice::addNotice(-10, $touristUid, "预订被导游审批拒绝: $reason");

                // 自动发起退款申请
                Order::refundSafety($orderNo);
            } 
        }
    }

    // 创建一批订单的结算交易
    public function createTransaction($orderIds)
    {
        // 批量获取订单的钱, 标题
        $query = DB::select()
            ->from('app_order')
            ->where('id', 'in', $orderIds)
            ->execute();

        $title  = '哇吖订单-';
        $money  = 0;
        $uid    = NULL;
        $shopId = NULL;
        $shopIdGroup = '';

        // 同步更新订单人民币金额
        foreach ($query as $rs)
        {
            $moneyRMB = (int) Util_ExchangeRate::Euro2RMB($rs['moneyTotal']);
            DB::update('app_order')
                ->set(array('moneyTotalRMB' => $moneyRMB))
                ->where('id', '=', $rs['id'])
                ->execute();

            $money += $moneyRMB;
            $title .= $rs['title'];

            if ($uid === NULL)
                $uid = $rs['uid'];
            else if ($uid != $rs['uid'])
                throw new Exception_Http_404("非同一个用户的订单");

            //if ($shopId === NULL)
            //    $shopId = $rs['shopId'];
            //else if ($shopId != $rs['shopId'])
            //    throw new Exception_Http_404("非同一个导游的订单");
            $shopIdGroup.=$rs['shopId']."|";
        }
        $shopIdGroup=rtrim($shopIdGroup,'|'); 
        $title = utf8::substr($title, 0, 120);

        // 插入交易记录
        $transAct = new Payment_Transaction;
        $transId  = $transAct->create($uid, $shopId,$shopIdGroup,$title, $money);
        if ($transId > 0)
        {
            DB::update('app_order')
            ->set(array('transactionId' => $transId))
            ->where('id', 'in', $orderIds)
            ->execute();
        }

        return $transId;
    }

    // 由交易模块发起，设置订单为已支付状态
    public function setOrdersPaidByTransactionId ($transId)
    {
        $row = array(
            'status'  => 1,  // 已付款，待导游确认
            'changed' => DB::expr('unix_timestamp(now())'),
            'paidTime'=> DB::expr('unix_timestamp(now())'),
        );

        $rows = DB::update('app_order')
            ->set($row)
            ->where('transactionId', '=', $transId)
            ->execute();

        if ($rows > 0)
        {
            $query = DB::select('id','uid','moneyTotalRMB','title', 'shopId', 'goodsType', 'goodsId')
                ->from('app_order')
                ->where('transactionId', '=', $transId)
                ->execute();

            foreach ($query as $rs)
            {
                // 记录订单日志
                $log = new Order_Log($rs['id']);
                $log->add("游客向哇吖支付成功");

                // 通知玩伴和游客有新的支付预订
		        $shopId = Arr::get($rs, 'shopId');
                $this->notice(Arr::get($rs, 'uid'),$shopId,Arr::get($rs, 'moneyTotalRMB'),Arr::get($rs, 'title'));
                // 更新路线/线路的订单预订数量
                $goods = Goods::factory($rs['goodsType'], $rs['goodsId']);
                $goods->updateCountsOrders();
            }

            return TRUE;
        }
        else
        {
            return FALSE;
        }
    }

    // 设置订单退款成功
    public function setOrderRefundSuccess ($orderId)
    {
            DB::update('app_order')
                ->set(array(
                    'status' => 6,
                    'changed' => DB::expr('unix_timestamp(now())'),
                ))
                ->where('id', '=', $orderId)
                ->execute();

            $log = new Order_Log($orderId);
            $log->add("订单退款成功");

            // 通知导游有新的支付预订
            $query = DB::select('uid', 'goodsType', 'goodsId')
                ->from('app_order')
                ->where('id', '=', $orderId)
                ->execute();

            $rs  = $query->current();
            $uid = Arr::get($rs, 'uid');
            Util_Notice::addNotice(-10, $uid, "订单退款成功，请查收");

            // 同步路线/线路的已预订订单数量
            $goods = Goods::factory($rs['goodsType'], $rs['goodsId']);
            $goods->updateCountsOrders();
    }

    // 设置订单结算状态
    public function setOrderBillStatus ($orderId, $status, $comment)
    {
        $orderId = self::getInternalOrderId ($orderId);
        DB::update('app_order')
            ->set(array(
                'shopBillStatus'  => $status,
                'shopBillComment' => $comment,
                'shopBillTime'    => DB::expr('unix_timestamp(now())'),
            ))
            ->where('id', '=', $orderId)
            ->execute();
    }

    public function notice($uid,$shopId,$money,$title){
        $tourist = Util_User::getUserInfo($uid);
        $guider = Util_User::getUserInfo($shopId);
        $tourist_name = Arr::get($tourist,'userFamily').Arr::get($tourist,'userName');
        $guider_name = Arr::get($guider,'userFamily').Arr::get($guider,'userName');
        $tourist_web_notice = "您预订了".$guider_name."的《{$title}》，并支付了".($money/100)."元，您可以去个人中心里的预定记录中查看订单。";
        $guider_web_notice = $tourist_name."预订了您的《{$title}》的申请，请尽快前去个人中心预定记录的预定申请中处理。";
        Util_Notice::addNotice($uid, $uid, $tourist_web_notice);
        Util_Notice::addNotice($uid, $shopId, $guider_web_notice);
        $mobile = Arr::get($guider,'userPhone');
        if($mobile != ""){
            $tpl_id = 1129823;
            $tpl_value = "#name1#=Hi&#name2#=tourist";
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile);
        }
        $mail = Arr::get($guider,'mail');
        if(!empty($mail)){
        $addr = url::site("/guider/orders_request", 'http', FALSE);
$body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑','Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}
a{line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑';}
</style>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>游客预定申请</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:150px;border:1px solid #96EDCC;border-radius:6px;
background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            <strong><font style="font-size:30px">{$tourist_name}</font>&nbsp;&nbsp;先生/女士预定了您的&nbsp;&nbsp;<font style="font-size:30px">{$title}</font>&nbsp;&nbsp;行程</strong></td>
            </tr>

             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
       <td>
       <table align="center" cellpadding="0" cellspacing="0" style="width:200px;height:50px;border:1px solid #F05C92;border-radius:4px;
background-color:#F05C92;vertical-align:middle;">
             <tbody>
            <tr>
            <td style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:60px;width:200px;height:50px;">
            <a href="{$addr}" target="_blank" style="text-decoration:none;color:#fff;width:200px;height:50px;">处理申请</a>
            </td>
            </tr>
             </tbody></table>
       </td>

</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如无法点击，复制以下地址至浏览器打开<br/>{$addr}</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;
//            $body  = "{$tourist_name}先生/女士预订了您的{$title}的申请，请点击下方链接处理申请 ".url::site("/guider/orders_request", 'http', FALSE)."，如无法点击，请复制地址至浏览器打开。";
            User_Subscribe::post_email($mail,'游客预定申请',$body);
        }
    }

    public function reject_notice($uid,$shopId,$title,$reason){
        $tourist = Util_User::getUserInfo($uid);
        $guider = Util_User::getUserInfo($shopId);
        $tourist_name = Arr::get($tourist,'userFamily').Arr::get($tourist,'userName');
        $guider_name = Arr::get($guider,'userFamily').Arr::get($guider,'userName');

        $tourist_notice = "{$guider_name} 拒绝了您《{$title}》的申请，原因如下：{$reason}，哇吖将在两个工作日之内向您执行原路退款操作。";

        Util_Notice::addNotice($shopId, $uid, $tourist_notice);
        $mobile = Arr::get($tourist,'userPhone');
        if($mobile != ""){
            $tpl_id = 1196351;
            $tpl_value = "#guide#={$guider_name}&#service#={$title}";
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile);
        }
        $mail = Arr::get($tourist,'mail');
        if(!empty($mail)){
            $tourist_yudingjilu_address = url::site("/tourist/orders", 'http', FALSE);
            $body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑',Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}

a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>抱歉！您的预定被玩伴拒绝</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>
<tr>
        <td width="600" height="100" border="0" align="center" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';">
<strong>玩伴&nbsp;<font style="font-size:40px;">{$guider_name}</font>&nbsp;拒绝了您关于&nbsp;<font style="font-size:40px;">{$title}</font>&nbsp;的预定申请</strong>
        </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="640" height="40" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #C1F4E1;border-top-left-radius:4px;
border-top-right-radius:4px;background-color:#C1F4E1;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="40" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">拒绝原因：</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:150px;border:1px solid #96EDCC;border-bottom-left-radius:4px;
border-bottom-right-radius:4px;background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">
            {$reason}</td>
            </tr>

             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
       <td>
       <table align="center" cellpadding="0" cellspacing="0" style="width:200px;height:50px;border:1px solid #F05C92;border-radius:4px;
background-color:#F05C92;vertical-align:middle;">
             <tbody>
            <tr>
            <td style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:60px;width:200px;height:50px;">
            <a href="{$tourist_yudingjilu_address}" target="_blank" style="text-decoration:none;color:#fff;width:200px;height:50px;">查看订单</a>
            </td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如无法点击，复制以下地址至浏览器打开<br/>{$tourist_yudingjilu_address}</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;
//            $body  = "由于{$reason}，哇吖玩伴{$guider_name}拒绝了您关于{$title}的申请，哇吖将在两个工作日之内向您执行原路退款操作。点击下方链接查看详情".url::site("/tourist/orders/track?type=track", 'http', FALSE)."，如无法点击，请复制地址至浏览器打开。";
            User_Subscribe::post_email($mail,'预定失败',$body);
        }
    }

    public function ok_notice($uid,$shopId,$title,$start_date,$end_date,$people_num,$money){
        $tourist = Util_User::getUserInfo($uid);
        $guider = Util_User::getUserInfo($shopId);
        $tourist_name = Arr::get($tourist,'userFamily').Arr::get($tourist,'userName');
        $guider_name = Arr::get($guider,'userFamily').Arr::get($guider,'userName');
        $date = $start_date;
        $start_date = date('Y年m月d日',strtotime($start_date));
        $end_date = date('Y年m月d日',strtotime($end_date));
        $tourist_notice = $guider_name."接受了您的《{$title}》的申请，您可以前去个人中心的预定记录查看订单信息。";

        Util_Notice::addNotice($shopId, $uid, $tourist_notice);
        $mobile_tourist = Arr::get($tourist,'userPhone');
        $mobile_guider = Arr::get($guider,'userPhone');
        if($mobile_guider != ""){
            $tpl_id = 1196395;
            $tpl_value = "#date#=".$date;
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile_guider);
        }
        $guider_mail = Arr::get($guider,'mail');
        if($mobile_tourist != ""){
            $tpl_id = 1196375;
            $tpl_value = "#tourist#={$tourist_name}&#start_date#={$start_date}&#end_date#={$end_date}&#service#={$title}&#people_num#={$people_num}&#money#={$money}&#guide#={$guider_name}&#phone_num#={$mobile_guider}&#email#={$guider_mail}";
            $sms_obj = new Util_YunPianSms();
            $sms_obj->send_sms_to_user_id($tpl_id, $tpl_value, $mobile_tourist);
        }

        $tourist_mail = Arr::get($tourist,'mail');
        if(!empty($tourist_mail)){
                $body = <<<DOC
                    <meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑',Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}

a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>


<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>订单确认</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>

<tr>


        <td width="800" height="100" border="0" align="center" colspan="2" style="font-size:40px;vertical-align:middle;font-family:'微软雅黑';color:#F05C92">
<strong>预定成功!</strong>
        </td>
</tr>

<tr>
        <td>
             <table width="640" height="40" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #C1F4E1;border-top-left-radius:4px;
border-top-right-radius:4px;background-color:#C1F4E1;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="40" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;"> 详情</td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:250px;border:1px solid #96EDCC;border-bottom-left-radius:4px;
border-bottom-right-radius:4px;background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">线路名称：<font style="font-size:30px">{$title}</font></td>
            </tr>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">游客姓名：<font style="font-size:30px">{$tourist_name}</font></td>
            </tr>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">出行日期：<font style="font-size:30px">{$start_date}-{$end_date}</font></td>
            </tr>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">出行人数：<font style="font-size:30px">{$people_num}&nbsp;人</font></td>
            </tr>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">支付金额：<font style="font-size:30px;color:#F05C92">{$money}&nbsp;元</font></td>
            </tr>

             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>

<tr>
        <td>
             <table width="640" height="240" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #FAF2E6;border-radius:4px;
background-color:#FAF2E6;color:#393939;">
             <tbody>
            <tr>
            <td width="93" height="240" align="left" rowspan="6" style="vertical-align:middle;padding-left:20px;"><img src="http://www.wayatrip.com/resource/images/mail_imgs1.png" style="width:93px;height:240px;"></td>
            <td width="563" height="40" align="left" ></td>
            </tr>
            <tr>
            <td width="527" height="40" align="left" style="font-size:30px;vertical-align:middle;font-family:'微软雅黑';vertical-align:middle;padding-left:15px;">玩伴信息：</td>
            </tr>
            <tr>
            <td width="527" height="40" align="center" style="font-size:30px;vertical-align:middle;font-family:'微软雅黑';vertical-align:middle;">{$guider_name}</td>
            </tr>
            <tr>
            <td width="527" height="40" align="center" style="font-size:30px;vertical-align:middle;font-family:'微软雅黑';vertical-align:middle;">Tel：{$mobile_guider}</td>
            </tr>
            <tr>
            <td width="527" height="40" align="center" style="font-size:30px;vertical-align:middle;font-family:'微软雅黑';vertical-align:middle;">Email：{$guider_mail}</td>
            </tr>
            <tr>
            <td width="527" height="40"></td>
            </tr>

             </tbody></table>
       </td>
</tr>

<tr>

       <td width="800" height="100" border="0" align="center" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';">
如遇任何问题，请联系哇吖客服：&nbsp;&nbsp;<font style="color:#96EDCC"><strong>400-889-7955</strong></font>
       </td>

</tr>

<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>

            <td width="175" height="200"></td>

            <td>

            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>

           </td>
           <td>

            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>

           </td>

           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;

            User_Subscribe::post_email($tourist_mail,'预定成功',$body);
        }
        if(!empty($guider_mail)){
            $guide_yudingjilu_address = url::site("/guider/orders_paid", 'http', FALSE);
            $body = <<<DOC
<meta charset="utf-8">
<style type="text/css">
body{ margin:0 auto; padding:0; font-family:'微软雅黑',Hiragino Sans GB', '华文细黑', 'STHeiti', 'Microsoft YaHei',
SimHei, 'Helvetica Neue', Helvetica, Arial, sans-serif;background-color:#fff; font-size:12px;}
a{color:#00a2ca; line-height:22px; text-decoration:none;}
a:hover{text-decoration:underline;color:#489E85;}
td{font-family:'微软雅黑i';}
</style>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" style="font-family:'微软雅黑';">
<tbody>
<tr>
        <td>
             <table style="width:800px;height:149px;">
             <tbody>
            <tr>
            <td><img src="http://www.wayatrip.com/resource/images/mail-imgs2.png" style="width:800px;height:149px;"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>

            <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#fff" height="74" style="font-family:'微软雅黑';">
              <tbody><tr>
                <td width="97" height="74" border="0" align="center" valign="middle" style="padding-left:20px;"><a href="http://www.wayatrip.com" target="_blank"><img src="http://www.wayatrip.com/resource/www/imgs/logo.png" alt="哇吖自由行" width="97" height="74" border="0"></a>
               </td>
                <td width="703" height="74" colspan="2" align="left" valign="middle" style="padding-left:30px;">
                <font style="font-size:30px;color:#489E85;"><strong>玩伴接受预定</strong></font>
                </td>
              </tr>
            </tbody></table>

        </td>
</tr>
<tr>
        <td width="800" height="100" border="0" align="center" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';">
<strong>您已接受&nbsp;<font style="font-size:40px;">{$tourist_name}</font>&nbsp;先生/女士关于&nbsp;<font style="font-size:40px;">{$title}</font>&nbsp;的预定申请</strong>
        </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:20px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="640" height="40" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #C1F4E1;border-top-left-radius:4px;
border-top-right-radius:4px;background-color:#C1F4E1;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="40" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">详情</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:150px;background-color:#96EDCC;color:#393939">
             <tbody>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">出行日期：<font style="font-size:30px">{$start_date}-{$end_date}</font></td>
            </tr>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">出行人数：<font style="font-size:30px">{$people_num}&nbsp;人</font></td>
            </tr>
            <tr>
            <td width="640" height="50" align="left" colspan="2" style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:20px;">支付金额：<font style="font-size:30px;color:#F05C92">{$money}&nbsp;元</font><br/><br/><br/><font style="font-size:12px;">游客支付金额=玩伴制定的路线或是活动的价格*110%<br/>(该资金由哇吖托管至旅行结束，届时哇吖将向玩伴执行打款操作，打款金额为玩伴制定的路线或是活动的价格)</font></td>
            </tr>

             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table align="center" cellpadding="0" cellspacing="0" style="width:640px;height:30px;background-color:#96EDCC;border:1px solid #96EDCC;border-bottom-left-radius:4px;
border-bottom-right-radius:4px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;">
             <tbody>
            <tr>
            <td width="800" height="50"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
       <td>
       <table align="center" cellpadding="0" cellspacing="0" style="width:200px;height:50px;border:1px solid #F05C92;border-radius:4px;
background-color:#F05C92;vertical-align:middle;">
             <tbody>
            <tr>
            <td style="font-size:20px;vertical-align:middle;font-family:'微软雅黑';padding-left:60px;width:200px;height:50px;">
            <a href="{$guide_yudingjilu_address}" target="_blank" style="text-decoration:none;color:#fff;width:200px;height:50px;">查看订单</a>
            </td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:50px;text-align:center;vertical-align:middle">
             <tbody>
            <tr>
            <td style="font-size:15px;">如无法点击，复制以下地址至浏览器打开<br/>{$guide_yudingjilu_address}</td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table style="width:800px;height:30px;">
             <tbody>
            <tr>
            <td width="800" height="30"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
<tr>
        <td>
             <table width="800" height="200" cellpadding="0" cellspacing="0" style="background-color:#252525;color:#fff;">
             <tbody>
            <tr>
            <td width="175" height="200"></td>
            <td>
            <table style="height:225px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">联系我们</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">国内：400-889-7955</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">法国：+33666015304</td>
            </tr>
            <tr>
            <td width="200" height="30" align="left" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';color:#fff;">邮箱：info@wayatrip.com</td>
            </tr>
            <tr>
            <td width="200" height="60" align="left" ></td>
            </tr>
            </tbody></table>
           </td>
           <td>
            <table style="height:250px;width:200px;color:#fff;">
             <tbody>
            <tr>
            <td width="200" height="50" align="center" style="font-size:15px;vertical-align:middle;font-family:'微软雅黑';padding-top:10px;color:#fff;">官方微信<br/>wayaziyouxing</td>
            </tr>
            <tr>
            <td width="200" height="100" align="center"><img src="http://www.wayatrip.com/resource/www/imgs/erweima.jpg" style="height:100px;width:100px"></td>
            </tr>
            <tr>
            <td width="200" height="50" ></td>
            </tr>
            </tbody></table>
           </td>
           <td width="150" height="200"></td>
            </tr>
             </tbody></table>
       </td>
</tr>
</tbody></table>
DOC;
            User_Subscribe::post_email($guider_mail,'订单确认',$body);
        }
    }
}
